package com.example.springboot.common;




import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor // 无参构造器
@AllArgsConstructor // 全参构造器
/*@JsonInclude(JsonInclude.Include.NON_NULL) // 当属性为null时不序列化*/
@Builder//建造者模式 链式创建对象
public class Result {
    public static final String CODE_SUCCESS = "200";
    public static final String CODE_AUTH_ERROR = "401";
    public static final String CODE_SYS_ERROR = "500";

    private String code; // 响应状态码
    private String msg; // 响应消息
    private Object data; // 响应数据

    public static Result success() {
        return new Result(CODE_SUCCESS, "请求成功", null);

        //利用build创建对象
       /* return Result.builder().code(CODE_SUCCESS).msg("请求成功").build();*/
    }

    public static Result success(Object data) {
        return new Result(CODE_SUCCESS, "请求成功", data);
    }

    public static Result error(String msg) {
        return new Result(CODE_SYS_ERROR, msg, null);
    }

    public static Result error(String code, String msg) {
        return new Result(code, msg, null);
    }

    public static Result error() {
        return new Result(CODE_SYS_ERROR, "系统错误", null);
    }


}